import 'package:faker/models/rss.dart';
import 'package:faker/service/rssapi.dart';

import 'package:connectivity/connectivity.dart';

abstract class BaseServices {

  Future<RssBean> getRss(route);
}

class Services implements BaseServices {

  BaseServices serviceApi;

  static final Services _instance = Services._internal();

  factory Services() => _instance;

  Services._internal();

  void setAppConfig(appConfig) {
    RssApi().setAppConfig(appConfig);
    serviceApi = RssApi();
  }

  @override
  Future<RssBean> getRss(name) async {
    var connectivityResult = await (Connectivity().checkConnectivity());
    if (connectivityResult == ConnectivityResult.mobile ||
        connectivityResult == ConnectivityResult.wifi) {
      return serviceApi.getRss(name);
    } else {
      throw Exception("No internet connection");
    }
  }


}
